#include "stm32.h"

// 模拟设备初始化（实际需初始化硬件接口）
int Device_Init() {
    printf("设备初始化完成\n");
    return 0;
}

// 模拟设备控制（实际需发送指令到硬件）
int Device_Control(DeviceCmd cmd, char *response, int max_len)
 {
    float temp,humidity;
    switch (cmd) {
        case CMD_BUZZER_ON:
            sprintf(response, "Buzzer turned ON");
            printf("模拟：蜂鸣器已开启\n");
            break;
        case CMD_BUZZER_OFF:
            sprintf(response, "Buzzer turned OFF");
            printf("模拟：蜂鸣器已关闭\n");
            break;
        case CMD_LED_ON:
            sprintf(response, "LED turned ON");
            printf("模拟：LED 已开启\n");
            break;
        case CMD_LED_OFF:
            sprintf(response, "LED turned OFF");
            printf("模拟：LED 已关闭\n");
            break;
        case CMD_GET_TEMP:
            // 模拟温度读取（实际需读取传感器）
            temp = 25.5 + (rand() % 10) / 10.0;
            sprintf(response, "Temperature: %.1f°C", temp);
            break;
        case CMD_GET_HUMIDITY:
            // 模拟湿度读取
            humidity = 45.0 + (rand() % 20);
            sprintf(response, "Humidity: %.1f%%", humidity);
            break;
        default:
            sprintf(response, "Unknown command");
            return -1;
    }
    return 0;
}